<template>
 <div class="e-form">
    <div class="tabs">
        <el-tabs tab-position="left" v-model="tabsName" @tab-click="onChangeTab">
            <el-tab-pane label="基本信息" name="baseInfo" :disabled="clickTabFlag">
            </el-tab-pane>
            <el-tab-pane label="主体信息" name="mainInfo" :disabled="clickTabFlag">
            </el-tab-pane>
            <el-tab-pane label="设备明细" name="contractList" :disabled="clickTabFlag">
            </el-tab-pane>
            <!-- 字段未绑完 -->
            <el-tab-pane label="合同条款" name="contractTerms" :disabled="clickTabFlag">
            </el-tab-pane>
            <el-tab-pane label="附件信息" name="attach" :disabled="clickTabFlag">
            </el-tab-pane>
            <el-tab-pane label="正式合同文件" name="formalContract" :disabled="clickTabFlag">
            </el-tab-pane>
            <el-tab-pane label="审核历史" name="auditHistory" :disabled="clickTabFlag">
            </el-tab-pane>
            <el-tab-pane label="变更历史" name="changeHistory" :disabled="clickTabFlag">
            </el-tab-pane>
            <div>
                <!-- 基本信息 -->
                <div id="baseInfoCon" class="con">
                    <div class="tabs-title" id="baseInfo">基本信息</div>
                    <div style="width: 100%" class="form" v-if="objFlag.flag1">
                        <el-form :model="formData" :label-width="formLabelWidth">
                            <el-row>
                                <el-col :span="12">
                                    <el-form-item label="合同编号：">
                                        <span>{{formData.billNo}}</span>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="合同名称：">
                                        <el-input v-model="formData.facilitySaleName" autocomplete="off"></el-input>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="12">
                                    <el-form-item label="不含税金额(元)：">
                                        <span>{{formData.amountWithoutTax}}</span>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="币种：">
                                        <el-select v-model="formData.currencyName" @change="changeCurrency" placeholder="请选择">
                                            <el-option
                                                v-for="(
                                                    item
                                                ) in currencyArr"
                                                :key="item.kvId"
                                                :label="item.kvKey"
                                                :value="item.kvKey"
                                            >
                                            </el-option>
                                        </el-select>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="12">
                                    <el-form-item label="税率%：">
                                        <el-input v-model="formData.taxRate"  v-enter-number autocomplete="off"></el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="税额(元)：">
                                        <el-input v-model="formData.tax" v-enter-number autocomplete="off"></el-input>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="12">
                                    <el-form-item label="合同金额(元)：">
                                        <span>{{formData. rmbAmount}}</span>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="状态：">
                                        <span>{{options.stateForm[formData.state]}}</span>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="12">
                                    <el-form-item label="经办人：">
                                        <span>{{formData.founderName}}</span>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="签约人：">
                                        <el-input v-model="formData.signatoryName" autocomplete="off">
                                            <i
                                                class="
                                                    el-icon-document-copy
                                                "
                                                slot="suffix"
                                            >
                                            </i>
                                        </el-input>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="12">
                                    <el-form-item label="签订日期：">
                                        <el-date-picker type="date" value-format="yyyy-MM-dd" placeholder="选择日期" v-model="formData.signingDate"></el-date-picker>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="录入日期：">
                                        <span>{{formData.gmtCreate}}</span>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="12">
                                    <el-form-item label="所属机构：">
                                        <span>{{formData.orgName}}</span>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="传输财务共享：">
                                        <span>{{formData.isEas}}</span>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="12">
                                    <el-form-item label="签订地点：">
                                        <SelectAddr v-model="ctAddressCode" @getLabel="getAddrLabel"
                                            lazy
                                            showCountry
                                            style="width:49%;"
                                        ></SelectAddr>
                                        <el-input v-model="formData.signingAddress
                                            " placeholder="详细地址" style="width:49%;margin-left:2%">
                                        </el-input>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="24">
                                    <el-form-item label="备注：">
                                        <el-input type="textarea" v-model="formData.remarks" autocomplete="off"></el-input>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="12">
                                    <el-form-item label="本位币：">
                                        <span>{{formData.baseCurName}}</span>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="人民币汇率：">
                                        <span>{{formData.rmbRate}}</span>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="12">
                                    <el-form-item label="本位币汇率：">
                                        <span>{{formData.baseCurRate}}</span>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                        </el-form>
                    </div>
                    <div class="seize-a-seat" v-else>
                        <i class="el-icon-loading"></i>
                    </div>
                </div>

                <!-- 主体信息 -->
                <div id="mainInfoCon" class="con">
                    <div class="tabs-title" id="mainInfo">主体信息</div>
                    <div style="width:100%" class="form" v-if="objFlag.flag2">
                        <el-form :model="formData" label-width="150px">
                            <div class="mainTitle">甲方信息</div>
                            <el-row>
                                <el-col :span="12">
                                    <el-form-item label="名称：">
                                        <el-input v-model="mainInfo.aOrgName" autocomplete="off"></el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="开户银行：">
                                        <el-input v-model="mainInfo.aBank" autocomplete="off"></el-input>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="12">
                                    <el-form-item label="开户账号：">
                                        <el-input v-model="mainInfo.aAccount" autocomplete="off"></el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="联系电话：">
                                        <el-input v-model="mainInfo.aTelephone" autocomplete="off"></el-input>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="12">
                                    <el-form-item label="法人代表：">
                                        <el-input v-model="mainInfo.aLegalPerson" autocomplete="off"></el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="传 真：">
                                        <el-input v-model="mainInfo.aFax" autocomplete="off"></el-input>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="12">
                                    <el-form-item label="委托代理：">
                                        <el-input v-model="mainInfo.aAgent" autocomplete="off"></el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="邮政编码：" >
                                        <el-input v-model="mainInfo.aPostalCode" autocomplete="off"></el-input>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="12">
                                    <el-form-item label="签订地点：">
                                        <SelectAddr v-model="aAddressCode" @getLabel="getAddrLabel"
                                            lazy
                                            showCountry
                                            style="width:49%;"
                                        ></SelectAddr>
                                        <el-input v-model="formData.aorgAddress
                                            " placeholder="详细地址" style="width:49%;margin-left:2%">
                                        </el-input>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <div class="mainTitle">乙方信息</div>
                            <el-row>
                                <el-col :span="12">
                                    <el-form-item label="招标：">
                                        <el-input v-model="mainInfo.bbiddingName" autocomplete="off"></el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="名称：">
                                        <el-input v-model="mainInfo.bOrgName" autocomplete="off"></el-input>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="12">
                                    <el-form-item label="统一社会信用代码：">
                                        <el-input v-model="mainInfo.bCreditCode" autocomplete="off"></el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="法人代表：">
                                        <el-input v-model="mainInfo.bLegalPerson" autocomplete="off"></el-input>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="12">
                                    <el-form-item label="开户银行：">
                                        <el-input v-model="mainInfo.bBank" autocomplete="off"></el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="开户账号：">
                                        <el-input v-model="mainInfo.bAccount" autocomplete="off"></el-input>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="12">
                                    <el-form-item label="联系电话：">
                                        <el-input v-model="mainInfo.bTelephone" autocomplete="off"></el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="邮政编码：">
                                        <el-input v-model="mainInfo. bPostalCode" autocomplete="off"></el-input>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="12">
                                    <el-form-item label="委托代理：">
                                        <el-input v-model="mainInfo.bAgent" autocomplete="off"></el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="传 真：">
                                        <el-input v-model="mainInfo.bFax" autocomplete="off"></el-input>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="12">
                                    <el-form-item label="签订地点：">
                                        <SelectAddr v-model="bAddressCode" @getLabel="getbAddrLabel"
                                            lazy
                                            showCountry
                                            style="width:49%;"
                                        ></SelectAddr>
                                        <el-input v-model="formData.borgAddress
                                            " placeholder="详细地址" style="width:49%;margin-left:2%">
                                        </el-input>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <div class="mainTitle">公正信息</div>
                            <el-row>
                                <el-col :span="12">
                                    <el-form-item label="公正机关：">
                                        <el-input v-model="mainInfo.impartialOrganName" autocomplete="off"></el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="公正日期：">
                                        <el-date-picker type="date" value-format="yyyy-MM-dd" placeholder="选择日期" v-model="mainInfo.impartialDate" style="width: 100%;"></el-date-picker>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="12">
                                    <el-form-item label="开户银行：">
                                        <el-input v-model="mainInfo.bank" autocomplete="off"></el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="开户账号：">
                                        <el-input v-model="mainInfo.account" autocomplete="off"></el-input>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="24">
                                    <el-form-item label="公正意见：" >
                                        <el-input type="textarea" v-model="mainInfo.impartialAdvice" autocomplete="off"></el-input>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                        </el-form>
                    </div>
                    <div class="seize-a-seat" v-else>
                        <i class="el-icon-loading"></i>
                    </div>
                </div>

                <!-- 合同清单 未绑定完全 -->
                <div id="contractListCon" class="con">
                    <div class="tabs-title" id="contractList">设备明细</div>
                    <div v-if="objFlag.flag3">
                        <div class="e-table">
                            <div class="top">
                                <div class="left">
                                    <div>
                                        <el-button size="small" type="primary" plain>新增</el-button>
                                        <el-button size="small" type="danger" plain>删除</el-button>
                                    </div>
                                </div>
                            </div>
                            <el-table
                                :data="contractListTable"
                                border
                                style="width: 100%; margin-bottom: 20px"
                            >

                                <el-table-column  type="index" label="序号" width="50">
                                </el-table-column>
                                <el-table-column prop="" label="设备名称" width="200">
                                </el-table-column>
                                <el-table-column prop="" label="设备类别" width="120">
                                </el-table-column>
                                <el-table-column prop="specifications" label="规格型号" width="120">
                                </el-table-column>
                                <el-table-column prop="" label="单位" width="100">
                                </el-table-column>
                                <el-table-column prop="" label="数量" width="100">
                                </el-table-column>
                                <el-table-column prop="" label="单价(元)" width="130">
                                </el-table-column>
                                <el-table-column prop="" label="金额(元)">
                                </el-table-column>
                            </el-table>
                        </div>
                    </div>
                    <div class="seize-a-seat" v-else>
                        <i class="el-icon-loading"></i>
                    </div>
                </div>

                <!-- 合同条款 -->
                <div id="contractTermsCon" class="con">
                    <div class="tabs-title" id="contractTerms">合同条款</div>
                    <div v-if="objFlag.flag4">
                        <div class="e-table">
                            <div class="mainTitle">通用合同条款</div>
                            <el-table
                                :data="commonCtTermsTable"
                                border
                                style="width: 100%; margin-bottom: 20px"
                            >
                                <el-table-column type="index" label="模板编号" width="100">
                                </el-table-column>
                                <el-table-column prop="mechanism" label="所属机构" width="250">
                                </el-table-column>
                                <el-table-column prop="templateCode" label="通用合同条款编号" width="270">
                                </el-table-column>
                                <el-table-column prop="clauseTemplate" label="合同条款名称" width="250">
                                </el-table-column>
                                <el-table-column prop="detailedQuery" label="条款明细查阅" class-name="blue-column">
                                    <template>
                                        <span>查看</span>
                                    </template>
                                </el-table-column>
                            </el-table>
                        </div>
                        <div class="e-table">
                            <div class="mainTitle">项目专用合同条款</div>
                            <div class="top">
                                <div class="left">
                                    <div>
                                        <el-button size="small" type="primary" plain>新增</el-button>
                                        <el-button size="small" type="primary" plain>删除</el-button>
                                    </div>
                                </div>
                            </div>
                            <el-table
                                :data="onlyCtTermsTable"
                                border
                                style="width: 100%; margin-bottom: 20px"
                            >
                                <el-table-column type="index" label="序号" width="100">
                                </el-table-column>
                                <el-table-column prop="entryCode" label="条目号" width="250">
                                </el-table-column>
                                <el-table-column prop="clauseContent" label="原条款内容" width="270">
                                </el-table-column>
                                <el-table-column prop="specialConditions" label="专用合同条款内容" >
                                </el-table-column>
                            </el-table>
                        </div>
                    </div>
                    <div class="seize-a-seat" v-else>
                        <i class="el-icon-loading"></i>
                    </div>
                </div>

                <!-- 附件信息 -->
                <div id="attachCon" class="con">
                    <div class="tabs-title" id="attach">附件信息</div>
                    <attach-comp :relationId="attachId" bucketName="subcontract" v-if="objFlag.flag5"/>
                    <div class="seize-a-seat" v-else>
                        <i class="el-icon-loading"></i>
                    </div>
                </div>

                <!-- 正式合同文件 -->
                <div id="formalContractCon" class="con">
                    <div class="tabs-title" id="formalContract">正式合同文件</div>
                    <div class="e-table" v-if="objFlag.flag6">
                        <div class="top">
                            <div class="left">
                                <div>
                                    <el-button size="small" type="primary" plain>下载</el-button>
                                    <el-button size="small" type="danger" plain>删除</el-button>
                                </div>
                            </div>
                        </div>
                        <el-table
                            :data="formalContractTable"
                            border
                            style="width: 100%"
                        >
                            <el-table-column type="selection" width="55">
                            </el-table-column>
                            <el-table-column  label="序号" type="index" width="200">
                            </el-table-column>
                            <el-table-column
                                prop="enclosureName"
                                label="文件名称"
                                width="200"
                            >
                            </el-table-column>
                            <el-table-column
                                prop="enclosureSize"
                                label="文件大小"
                                width="130"
                            >
                            </el-table-column>
                            <el-table-column
                                prop="gmtCreate"
                                label="上传时间"
                                width="130"
                            >
                            </el-table-column>
                            <el-table-column
                                prop="uploadName"
                                label="上传人"
                                width="130"
                            >
                            </el-table-column>
                            <el-table-column
                                prop="ctState"
                                label="状态"
                            >
                            </el-table-column>
                        </el-table>
                    </div>
                    <div class="seize-a-seat" v-else>
                        <i class="el-icon-loading"></i>
                    </div>
                </div>

                <!-- 审核历史 -->
                <div id="auditHistoryCon" class="con">
                    <div class="tabs-title" id="auditHistory">审核历史</div>
                    <div class="e-table" v-if="objFlag.flag7">
                        <el-table
                            :data="auditHistoryTable"
                            border
                            style="width: 100%"
                        >
                            <el-table-column prop="auditLevel" label="审核级次" width="150">
                            </el-table-column>
                            <el-table-column prop="examineName" label="审核人" width="150">
                            </el-table-column>
                            <el-table-column
                                prop="examinePost"
                                label="审核人岗位"
                                width="150"
                            >
                            </el-table-column>
                            <el-table-column prop="notificationTime" label="通知时间" width="150">
                            </el-table-column>
                            <el-table-column prop="gmtCreate" label="审核时间" width="150">
                            </el-table-column>
                            <el-table-column prop="examineOpinion" label="审核意见">
                            </el-table-column>
                        </el-table>
                    </div>
                    <div class="seize-a-seat" v-else>
                        <i class="el-icon-loading"></i>
                    </div>
                </div>

                <!-- 变更历史 -->
                <div id="changeHistoryCon" class="con">
                    <div class="tabs-title" id="changeHistory">变更历史</div>
                    <div class="e-table" v-if="objFlag.flag8">
                        <el-table
                            :data="changeHistoryTable"
                            @cell-click="tableDbShow"
                            border
                            style="width: 100%"
                        >
                            <el-table-column fixed label="操作" width="100">
                                <template slot-scope="scope">
                                    <i
                                        id="iconEdit"
                                        style="
                                            cursor: pointer;
                                            font-size: 20px;
                                        "
                                        class="el-icon-edit"
                                        @click="tableDbEdit(scope.row.billId)"
                                    ></i>
                                </template>
                            </el-table-column>
                            <el-table-column prop="timeOfChange" label="变更期数" width="100">
                            </el-table-column>
                            <el-table-column prop="billNo" label="变更编号" class-name="blue-column" width="200">
                            </el-table-column>
                            <el-table-column prop="dateOfChange" label="变更日期"  width="120">
                            </el-table-column>
                            <el-table-column prop="amount" label="原合同金额(元)" width="130">
                            </el-table-column>
                            <el-table-column prop="changeAmount" label="变更金额(元)"  width="130">
                            </el-table-column>
                            <el-table-column prop="amountAfterChange" label="变更后合同金额(元)"  width="150">
                            </el-table-column>
                            <el-table-column prop="state" label="状态"  width="100">
                                <template slot-scope="scope">
                                    <span>{{options.stateForm[scope.row.state]}}</span>
                                </template>
                            </el-table-column>
                            <el-table-column prop="isFinancialSharing" label="传输财务共享">
                            </el-table-column>
                        </el-table>
                    </div>
                    <div class="seize-a-seat" v-else>
                        <i class="el-icon-loading"></i>
                    </div>
                </div>
            </div>
        </el-tabs>
    </div>
    <div class="buttons">
        <el-button type="primary" size="small" style="background: #2e61d7" @click="goCtChangePage"
            >变更</el-button
        >
        <el-button type="primary" size="small" style="background: #2e61d7"
            >打印</el-button
        >
        <el-button type="primary" size="small" style="background: #2e61d7"
            >审核</el-button
        >
        <el-button type="primary" size="small" style="background: #2e61d7" @click="addSave"
            >保存</el-button
        >
        <el-button type="primary" size="small" style="background: #2e61d7" @click="submit"
            >保存并提交</el-button
        >
        <el-button  type="danger" size="small"
            >撤回</el-button
        >
        <el-button  type="danger" size="small"
        @click="ctDelete"
            >删除</el-button
        >
        <el-button type="danger" size="small"
            >作废</el-button
        >
        <el-button size="small" @click="handleClose">关闭</el-button>
    </div>
    <div id="seat" :style="{height: seatHeight + 'px'}"></div>
 </div>
</template>

<script>
import '@/utils/jquery.scrollTo.min'
import { mapState } from 'vuex'
import SelectAddr from '@/components/common/addrComp'
import AttachComp from '@/components/common/attachIndex'
import fn from '@/utils/checkEmpty.js'
import equipmentIncome from '@/api/balanceContractApi/equipmentIncome.js'
import call from '@/api/balanceContractApi/getCurrency.js'
export default {
    data () {
        return {
            //基本信息表单数据
            formData: {
                'amountWithoutTax': null,
                'baseCurAmount': null,
                'baseCurName': '',
                'baseCurRate': null,
                'billId': '',
                'billNo': '',
                'changeState': null,
                'contractType': null,
                'contractTypeName': '',
                'currencyName': '',
                'facilitySaleName': '',
                'founderName': '',
                'isEas': null,
                'orgName': '',
                'remarks': '',
                'rmbAmount': null,
                'rmbRate': null,
                'signatoryName': '',
                'signingAddress': '',
                'signingArea': '',
                'signingAreaCode': '',
                'signingDate': '',
                'state': null,
                'tax': null,
                'taxRate': null,
                'timeOfChange': null
            },
            //主体信息表单数据
            mainInfo: {
                'aaccount': '',
                'aagent': '',
                'abank': '',
                'account': '',
                'acreditCode': '',
                'afax': '',
                'alegalPerson': '',
                'aorgAddress': '',
                'aorgArea': '',
                'aorgAreaCode': '',
                'aorgId': '',
                'aorgName': '',
                'apostalCode': '',
                'atelephone': '',
                'baccount': '',
                'bagent': '',
                'bank': '',
                'bbank': '',
                'bcreditCode': '',
                'bfax': '',
                'blegalPerson': '',
                'borgAddress': '',
                'borgArea': '',
                'borgAreaCode': '',
                'borgId': '',
                'borgName': '',
                'bpostalCode': '',
                'btelephone': '',
                'facilityIncomeId': '',
                'facilityLeaseOutInfoId': '',
                'impartialAdvice': '',
                'impartialDate': '',
                'impartialOrganId': '',
                'impartialOrganName': ''
            },
            saveData: {
                'amountWithoutTax': null,
                'aorgName': '',
                'auditTime': '',
                'auditorId': '',
                'auditorName': '',
                'auditorPosition': '',
                'baseCurAmount': null,
                'baseCurId': '',
                'baseCurName': '',
                'baseCurRate': null,
                'billId': '',
                'billNo': '',
                'borgName': '',
                'changeState': null,
                'contractType': null,
                'contractTypeName': '',
                'currencyId': '',
                'currencyName': '',
                'easId': '',
                'entryAndExitFee': null,
                'facilityIncomeName': '',
                'founderId': '',
                'founderName': '',
                'gmtCreate': '',
                'gmtModified': '',
                'isEas': null,
                'leaseType': null,
                'modifierId': '',
                'modifierName': '',
                'nullifyCreated': '',
                'nullifyCreator': '',
                'nullifyCreatorId': '',
                'nullifyDescription': '',
                'nullifyReason': '',
                'orgId': '',
                'orgName': '',
                'remarks': '',
                'rmbAmount': null,
                'rmbId': '',
                'rmbName': '',
                'rmbRate': null,
                'signatoryId': '',
                'signatoryName': '',
                'signingAddress': '',
                'signingArea': '',
                'signingAreaCode': '',
                'signingDate': '',
                'state': null,
                'tax': null,
                'taxRate': null,
                'timeOfChange': null
            },
            formLabelWidth: '180px',
            tableData1: [],
            tabsName: 'baseInfo',
            screenWidth: 0,
            screenHeight: 0,
            lastConHeight: 0,
            clickTabFlag: false, // 如果手动点击时，则不做滚动事件逻辑，只有滚动屏幕时才走滚动事件逻辑
            contractListTable: [], //设备明细表格数据
            commonCtTermsTable: [], //通用合同条款表格数据
            onlyCtTermsTable: [], //项目专用合同条款表格数据
            attachTable: [], //附件信息表格数据
            auditHistoryTable: [], //审核历史表格数据
            formalContractTable: [], //正式合同文件表格数据
            changeHistoryTable: [], //变更历史表格数据
            ctAddressCode: [],
            aAddressCode: [],  //甲方地址
            bAddressCode: [],  //乙方地址
            cAddressCode: [],  //运输单位地址
            objFlag: {   //判断是否转圈圈
                flag1: false,
                flag2: false,
                flag3: false,
                flag4: false,
                flag5: false,
                flag6: false,
                flag7: false,
                flag8: false,
            },
            currencyArr: [], //币种
            billid: '',
        }
    },
    created () {
        //获取币种
        call.getCurrency().then(res=> this.currencyArr = res)
    },
    mounted () {
        this.getBasic()
        // 获取最后一个内容区域的高度，计算底部空白
        this.getLastConHeight()
        // 保存所有tabName
        const arr = ['baseInfo', 'mainInfo', 'contractList', 'contractTerms', 'attach', 'formalContract', 'auditHistory', 'changeHistory']

        let $idsTop = []
        window.addEventListener('scroll', () => {
            // 如果手动点击时，则不做滚动事件逻辑，只有滚动屏幕时才走滚动事件逻辑
            if (this.clickTabFlag) {
                return
            }

            if (!$idsTop[$idsTop.length - 1]) {
                $idsTop = arr.map(item => {
                    const itemTop = document.getElementById(item).offsetTop
                    return itemTop
                })
            }
            const scrollTop = document.documentElement.scrollTop || document.body.scrollTop
            // 倒序查找
            let curLocal = 0
            for (let len = $idsTop.length, i = len - 1; i >= 0; i--) {
                let item = $idsTop[i]
                if ((scrollTop + 1) >= item) {
                    curLocal = i
                    break
                }
            }
            // 设置对应tabName
            this.tabsName = arr[curLocal]
            this.queryData(this.tabsName)
        })

        this.screenWidth = document.documentElement.clientWidth - this.topHeight
        this.screenHeight = document.documentElement.clientHeight - this.topHeight
        window.addEventListener('resize', () => {
            this.screenWidth = document.documentElement.clientWidth - this.topHeight
            this.screenHeight = document.documentElement.clientHeight - this.topHeight
            $idsTop = arr.map(item => {
                const itemTop = document.getElementById(item).offsetTop
                return itemTop
            })
        })
    },
    computed: {
        ...mapState({
            options: state => state.contract.ctClassify
        }),
        // 填补底部空白，以使高度够滚动
        seatHeight () {
            return this.screenHeight - 72 - this.lastConHeight
        },
        attachId () {
            return this.$route.query.billid
        }
    },
    methods: {
        //选择币种的事件
        changeCurrency () {
            const obj = this.currencyArr.find(item=>item.kvKey === this.formData.currencyName)
            this.formData.currencyId = obj.kvId
        },
        //更新数据
        addSave () {
            if(this.ctAddressCode.length > 0) {
                this.formData.signingAreaCode = this.ctAddressCode.join('-') //行政编码
            }
            this.saveData = Object.assign(this.saveData, this.formData)
            this.saveData.facilityIncomeName = this.formData.facilitySaleName
            equipmentIncome.saveFacilityIncome(this.saveData).then(()=>{
                this.clientPop('suc', '保存成功')
                this.getBasic()
            })
        },
        //提交数据
        submit () {
            equipmentIncome.findByIdsubmit(this.billid).then(()=>{
                this.clientPop('suc', '提交成功', this.handleClose)
            })
        },
        //去合同变更新增页面
        goCtChangePage () {
            const billid = this.billid
            this.$router.push({
                path: '/ctEquimentSaleChangeAdd',
                query: { billid }
            })
        },
        //单击变更编号
        tableDbShow (row, column) {
            const billid = row.billId
            if(column.label === '变更编号') {
                this.$router.push({ path: '/ctEquimentSaleChangeShow', query: { billid } })
            }
        },
        //点击变更编辑页面
        tableDbEdit (billid) {
            this.$router.push({
                path: '/ctEquimentSaleChangeEdit',
                query: { billid }
            })
        },
        //取消
        handleClose () {
            this.$router.go(-1)
        },
        // 获取地址对应中文
        getAddrLabel (val) {
            this.formData.signingArea = val.join('-')
        },
        //获取甲方地址对应中文
        getaAddrLabel (val) {
            this.mainInfo.aorgArea = val.join('-')
        },
        //获取乙方方地址对应中文
        getbAddrLabel (val) {
            this.mainInfo.borgArea = val.join('-')
        },
        //判断是否为空
        checkEmpty (datas) {
            return fn.checkEmpty(datas)
        },
        //根据点击不同的tab,调用不同的接口
        queryData (name) {
            switch(name) {
            case 'baseInfo':
                if(this.checkEmpty(this.formData)) this.getBasic()
                break
            case 'mainInfo':
                if(this.checkEmpty(this.mainInfo)) this.getMain()
                break
            case 'contractList':
                if(this.checkEmpty(this.contractListTable)) this.getContractList()
                break
            case 'contractTerms':
                if(this.checkEmpty(this.commonCtTermsTable) || this.checkEmpty(this.onlyCtTermsTable)) this.getContractTerms()
                break
            case 'attach':
                if(this.checkEmpty(this.attachTable)) this.getAttach()
                break
            case 'formalContract':
                if(this.checkEmpty(this.formalContractTable)) this.getFormalContract()
                break
            case 'auditHistory':
                if(this.checkEmpty(this.auditHistoryTable)) this.getAuditHistory()
                break
            case 'changeHistory':
                if(this.checkEmpty(this.changeHistoryTable)) this.getChangeHistory()
                break
            }
        },
        //根据id查询基本信息
        getBasic () {
            this.billid = this.$route.query.billid
            equipmentIncome.findFacilitySaleById(this.billid).then(res=>{
                if(res.signingAreaCode) {
                    this.ctAddressCode = res.signingAreaCode.split('-')
                }
                this.formData = res
                this.objFlag.flag1 = true
            })
        },
        //根据id查询主体信息
        getMain () {
            this.objFlag.flag2 = true
        },
        //根据id查询合同清单
        getContractList () {
            this.objFlag.flag3 = true
        },
        //根据id查询合同条款
        getContractTerms () {
            this.objFlag.flag4 = true
        },
        //根据id查询附件信息
        getAttach () {
            this.objFlag.flag5 = true
        },
        //根据id查询正式合同文件
        getFormalContract () {
            this.objFlag.flag6 = true
        },
        //根据id审核历史
        getAuditHistory () {
            this.objFlag.flag7 = true
        },
        //根据id查询变更历史
        getChangeHistory () {
            equipmentIncome.findByIdchangeHistory(this.billid).then(res=>{
                this.changeHistoryTable = res
                this.objFlag.flag8 = true
            })
        },
        //点击删除
        ctDelete () {
            this.clientPop(
                'info',
                this.oneDeleteErr,
                this.delData
            )
        },
        delData () {
            equipmentIncome.findByIdDelete(this.billid).then(()=>{
                this.clientPop('suc', '删除成功', this.goListPage)
            })
        },
        goListPage () {
            this.$router.push('/equimentSalesContract')
        },
        onChangeTab (e) {
            $.scrollTo(`#${e.name}`, 500)
            // 如果手动点击时，则不做滚动事件逻辑，只有滚动屏幕时才走滚动事件逻辑
            this.clickTabFlag = true
            // 动画结束后，恢复状态
            setTimeout(() => {
                this.clickTabFlag = false
            }, 600)
            this.queryData(e.name)
        },
        // 获取最后一个内容区域的高度，计算底部空白
        getLastConHeight () {
            let si = setInterval(() => {
                // 因为dom异步加载，通过轮询找到渲染后的dom，获取高度
                if (document.getElementById('recodesCon')) {
                    const lastConHeight = document.getElementById('recodesCon').offsetHeight
                    console.log('lastConHeight: ', lastConHeight)
                    this.lastConHeight = lastConHeight
                    clearInterval(si)
                    si = null
                }
            }, 100)
        },
    },
    components: {
        SelectAddr,
        AttachComp
    }
}

</script>

<style lang='scss' scoped>
.mainTitle{
    box-sizing: border-box;
    width:100%;
    height: 40px;
    line-height: 40px;
    background: rgb(246,246,246);
    border: 1px solid rgb(236, 236, 236);
    margin: auto;
    margin-bottom: 15px;
    padding-left: 10px;
}
.separ{
   width: 30px;
   height: 40px;
   line-height: 18px;
   text-align: center;
}
.e-table{
    min-height: auto;
    background: #fff;
}
.upload {
    margin: 20px auto;
    display: flex;
    justify-content: center;
    text-align: center;
}

.upload-demo {
    display: flex;
    justify-content: center;
    align-items: center;
}

::v-deep.el-input--suffix .el-input__inner {
    padding-right: 5px;
}

</style>